# -*- coding:utf -*-
import socket
import os

#监听主机
#Windows主机IP
host = "172.16.69.105" 

#Linux主机IP
#host = "192.168.233.1"

if os.name == "nt":
    socket_protocol = socket.IPPROTO_IP
else:
    socket_protocol = socket.IPPROTO_ICMP

sniffer = socket.socket(socket.AF_INET,socket.SOCK_RAW,socket_protocol)
sniffer.bind((host,8080))
sniffer.setsockopt(socket.IPPROTO_IP,socket.IP_HDRINCL,1)# 设置在捕获的数据包中包含IP头


if os.name == "nt":# 启用混杂模式
    sniffer.ioctl(socket.SIO_RCVALL,socket.RCVALL_ON)

print(sniffer.recvfrom(65565))# 读取单个数据包

if os.name == "nt":# 关闭混杂模式
    sniffer.ioctl(socket.SIO_RCVALL,socket.RCVALL_OFF)
